package com.tianxiao.faas.application.web.corner;

import com.tianxiao.faas.api.param.corner.*;
import com.tianxiao.faas.application.aop.AuthenticationContextHolder;
import com.tianxiao.faas.biz.service.corner.AiHistoryService;
import com.tianxiao.faas.common.access.Access;
import com.tianxiao.faas.common.result.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/app/ai/history")
public class AiHistoryController {

    @Resource
    private AiHistoryService aiHistoryService;

    @RequestMapping(value = "/order")
    @Access
    public Result<List<OrderHistoryResult>> orderHistory(@RequestBody OrderHistoryParam param) {
        Long userId = AuthenticationContextHolder.currentContext().getUserId();
        List<OrderHistoryResult> results = aiHistoryService.orderHistory(param, userId);
        Integer count = aiHistoryService.orderHistoryCount(param, userId);

        return Result.builder().success(true).data(results).totalCount(count).pageNo(param.getPage())
                .pageSize(param.getPageSize()).totalPage();
    }

    @RequestMapping(value = "/order/details")
    @Access
    public Result<OrderHistoryDetailsResult> orderDetails(Long id) {
        OrderHistoryDetailsResult orderHistoryDetailsResult = aiHistoryService.orderDetails(id);
        return Result.builder().data(orderHistoryDetailsResult).success(true);
    }

    @RequestMapping(value = "/report")
    @Access
    public Result<List<ReportHistoryResult>> reportHistory(BasePageParam param) {
        Long userId = AuthenticationContextHolder.currentContext().getUserId();
        List<ReportHistoryResult> results = aiHistoryService.reportHistory(param, userId);
        Integer count = aiHistoryService.reportHistoryCount(userId);

        return Result.builder().success(true).data(results).totalCount(count).pageNo(param.getPage())
                .pageSize(param.getPageSize()).totalPage();
    }
}
